function openMap(url, width, height, toolbar) {
    window.open(url,'map','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+toolbar+',resizable=0,width='+width+',height='+height);
    return false;
}

function apparition(id) {
    if (document.getElementById(id).style.display == "none")
    document.getElementById(id).style.display = "block";
    else document.getElementById(id).style.display = "none";
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function hasAttribute(element,attribute,val) {
        var has=element.getAttribute(attribute);
        if (has == val)
        {
            return false;
        }
        else {
            return false;
        }
}

function formValidation(id) {
    var oForm = id;
    var doSubmit = true;
    for(var i=0; i<oForm.length; i++){
        var oE = oForm[i]
        if(eval(oE.getAttribute('required'))){
            if(oE.type=="text"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="password"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { 
                    if (!valid_pass())
                    { setError(oE, 0); doSubmit = false; }
                    else {setError(oE, 1); }
                }
            }
            else if(oE.type=="textarea"){
                if(oE.value == ""){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="checkbox"||oE.type=="radio"){
                var aE = oForm[oE.name];
                var checked = false;
                if(aE.length){
                    for(var j=0; j<aE.length; j++){
                        checked = (checked||aE[j].checked);
                    }
                }
                else { checked = aE.checked; }
                if(!checked) { setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="select-one"){
                if(oE.selectedIndex==0){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
            else if(oE.type=="select-multiple"){
                if(oE.selectedIndex==-1){ setError(oE, 0); doSubmit = false; }
                else { setError(oE, 1); }
            }
        }

        if(eval(oE.getAttribute('emailcheck'))){
            var isOK = true;
            var aEmail = oE.value.split("@");
            if(aEmail.length!=2) { isOK = false; }
            else {
                if(aEmail[0].length<1) { isOK = false; }
                else {
                    aEmail = aEmail[1].split(".");
                    if(aEmail.length<2) { isOK = false; }
                    else{
                        for(var z=0; z<aEmail.length; z++){
                            if(aEmail[z].length<2) { isOK = false; }
                        }
                    }
                }
            }
            
            if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }

        }

        if(eval(oE.getAttribute('telephonecheck'))){
            var isOK = true;
            var aTel = oE.value.split("-");
            var regex = new RegExp(/^(01|02|03|04|05|06|08)-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}/gi);
            if( (oE.value.length!=14) || (aTel.length != 5) ) { isOK = false; }
            else {
                  if (regex.aTel == false) { isOK = false; }
                }
            
            if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }

        }

        if(eval(oE.getAttribute('urlcheck'))){
            var isOK = true;
            var aUrl = oE.value.split("//");
            var bUrl = aUrl[1].split(".blog4trade.com");
            if( (bUrl[0].length < 4) || (bUrl[0].length > 50) ) { isOK = false; }
            else {
                    if ( (bUrl[1] != "") && (bUrl[1] != "/") ) { isOK = false; }
                }

            if(!isOK) { setError(oE, 0); doSubmit = false; }
            else { setError(oE, 1); }

        }

    }
    if (doSubmit) {
        return oForm.submit();
    }
}

function setError(oFld, ok){
    document.getElementById(oFld.getAttribute('txtspan')).className = ok?null:"required";
}
